package com.mvu.banana.tools;

import java.util.HashMap;
import java.util.Map;

/**
 * Class description...
 *
 * @author gantz
 */
public class JavaAnnotation {
  private String name;
  private Map<String, String> values;

  public JavaAnnotation(JavaClass parent, Class annotationClass) {
    parent.importClass(annotationClass);
    name = annotationClass.getSimpleName();
  }

  public String print() {
    StringBuilder builder = new StringBuilder("@").append(name);
    if (values != null) {
      builder.append("(");
      int i = 0;
      for (Map.Entry<String, String> entry : values.entrySet()) {
        if(i > 0){
          builder.append(", ");
        }
        i++;
        builder.append(entry.getKey()).append(" = ").append(entry.getValue());
      }
      builder.append(")");
    }
    return builder.toString();
  }

  public JavaAnnotation withValue(String name, String value) {
    if (values == null) {
      values = new HashMap<String, String>();
    }
    values.put(name, value);
    return this;
  }
}
